const path = require('path')

function resolve (dir) {
  return path.join(__dirname, dir)
}

// 引入docs的全局css变量
function addStyleResource (rule) {
  rule.use('style-resource')
    .loader('style-resources-loader')
    .options({
      patterns: [
        path.resolve(__dirname, 'docs/styles/var.styl')
      ]
    })
}

module.exports = {
  // 入口文件改成docs目录
  pages: {
    index: {
      entry: 'docs/main.js',
      template: 'public/index.html',
      filename: 'index.html'
    }
  },
  publicPath: '/door-ui/',
  // 扩展webpack配置，使packages加入编译
  chainWebpack: config => {
    const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
    types.forEach(type => addStyleResource(config.module.rule('stylus').oneOf(type)))
    config.resolve.alias
      .set('@', resolve('docs'))
      .set('themes', resolve('themes'))
      .set('packages', resolve('packages'))
    config.module
      .rule('js')
      .include.add('/packages')
      .end()
      .use('babel')
      .loader('babel-loader')
      .tap(options => {
        return options
      })
  }
}
